﻿/*
 *  创建者：    
 *      zlk
 *  创建时间：
 *      2011-7-25
 *  文件说明：
 *     系统参数配置的相关读写(操作web.config)
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;
using System.Xml;
using System.Web;

namespace Sunimage.Spjg.Common
{
    /// <summary>
    /// 系统配置文件
    /// </summary>
    public class SystemConfiguration
    {
        /// <summary>
        /// 系统配置工商局默认的密码
        /// </summary>
        /// <returns></returns>
        public static string GetDefaultGsjUserPassword()
        {
            return ConfigurationManager.AppSettings["defaultGsjUserPassword"];
        }
        public static string GetDefaultCommercerUserPassword()
        {
            return ConfigurationManager.AppSettings["defaultCommercerUserPassword"];
        }

        public static string GetFileDirectory()
        {
            return ConfigurationManager.AppSettings["file"];
        }

        /// <summary>
        /// 系统配置的登录页面
        /// </summary>
        /// <returns></returns>
        public static string GetLoginPage()
        {
            return ConfigurationManager.AppSettings["loginPage"];
        }

        public static string GetShiJianGuGsjCode()
        {
            return "430703001";
        }

        /// <summary>
        /// 获取同步商户的模板文件位置
        /// </summary>
        /// <returns></returns>
        public static string GetSyncCommercerTemplateFilePath()
        {
            string path = GetFileDirectory() + Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar + "同步商户表.xls";
            return path;
        }



        /// <summary>
        /// 获取生产企业的模板文件位置
        /// </summary>
        /// <returns></returns>
        public static string GetEnterpriseTemplateFilePath()
        {
            string path = GetFileDirectory() + Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar + "厂商条码库.xls";
            return path;
        }

        /// <summary>
        /// 获取生产企业的模板文件位置
        /// </summary>
        /// <returns></returns>
        public static string GetProductPurchaseTemplateFilePath()
        {
            string path = GetFileDirectory() + Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar + "进货信息.xls";
            return path;
        }

        /// <summary>
        /// 获取生产企业的模板文件位置
        /// </summary>
        /// <returns></returns>
        public static string GetCheckProductTemplateFilePath()
        {
            string path = GetFileDirectory() + Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar + "设置供货关系.xls";
            return path;
        }
        /// <summary>
        /// 获取供货商模板位置
        /// </summary>
        /// <returns></returns>
        public static string GetSupplyerTemplateFilePath()
        {
            return GetFileDirectory() + Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar + "供货商.xls";
        }

        /// <summary>
        /// 获取刷机 系统数据信息的票号前缀
        /// </summary>
        /// <returns></returns>
        public static string GetShuajiPreCode()
        {
            XmlNode node = GetNode("PreCode");
            return node.Attributes["value"].Value;
        }
        /// <summary>
        /// 获取刷机 系统数据信息的流水号
        /// </summary>
        /// <returns></returns>
        public static string GetSerialData()
        {
            XmlNode node = GetNode("SerialData");
            return node.Attributes["value"].Value;
        }
        /// <summary>
        /// 获取刷机 系统数据信息的服务器IP地址
        /// </summary>
        /// <returns></returns>
        public static string GetServerIp()
        {
            XmlNode node = GetNode("ServerIp");
            return node.Attributes["value"].Value;
        }
        /// <summary>
        /// 获取刷机 系统数据信息的服务器端口
        /// </summary>
        /// <returns></returns>
        public static string GetServerPort()
        {
            XmlNode node = GetNode("ServerPort");
            return node.Attributes["value"].Value;
        }
        /// <summary>
        /// 获取刷机 系统数据信息的票据机的保存时间
        /// </summary>
        /// <returns></returns>
        public static string GetSaveDays()
        {
            XmlNode node = GetNode("SaveDays");
            return node.Attributes["value"].Value;
        }

        private static XmlNode GetNode(string nodeName)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(HttpContext.Current.Server.MapPath("~/config/SysConfig.xml"));
            XmlNode node = xmldoc.SelectSingleNode("configuration/"+nodeName);
            return node;
        }
    }
}
